/**
 * Created by yoyoyk on 2017/3/8.
 */
import React , {Component}from 'react';
import {Button,Modal} from 'fly';
import Confirm from '../../common/Confirm'
import Select from '../../common/Select'
import UpdateDepartmentBatchMutation from "./mutation/UpdateDepartmentBatchMutation";
import Relay from "react-relay";

/*业务平台>人员管理>编辑部门>批量修改部门*/

export default class Muchmodifypart extends React.Component {
    constructor(props){
        super(props);
        this.state = {
            visible: false,
            uidlist:[],
            departname:{},
            partid :0,
            departmentforchoose:[],
        }
        this.Style={};
        this.enterpriseId = sessionStorage.getItem('enterpriseId');
    }

    componentWillMount() {
        this.Style.muchmodifypartview={
            textAlign:"center",
            display:"block",
            border:"3px solid green"
        }
        this.Style.muchmodifypartview.width = 400;
        this.Style.muchmodifypartview.height = 200;
        this.Style.muchmodifypartview.fontSize = 30;

        this.Style.muchmodifypartview={
            width:"634px",
            height:"44px",
            paddingLeft:"18px",
            lineHeight:"44px",
            display:"block",
            background:"#f2f2f2",
            marginBottom:49
        }
    }

    state = { visible: false }
    showModal = () => {
        this.setState({
            visible: true,
        });
    }
    handleOk = (e) => {
        this.setState({
            visible: false,
        });
    }
    handleCancel = (e) => {
        this.setState({
            visible: false,
        });
    }

    createuser(){
        let depid;
        if(this.refs.partname.state.value==''){
            depid =  this.refs.partname.state.defaultValue
        }else{
            depid = this.refs.partname.state.value;
        }
        Relay.Store.commitUpdate(
            new UpdateDepartmentBatchMutation({
                enterpriseId: this.enterpriseId,
                depId:depid,
                ids:this.state.uidlist.join(',')
            }),
            {
                onFailure: () => {

                },
                onSuccess: (response) => {
                    let errorCode = response.updateDepartmentBatch.updateDepartmentBatch.errorCode;
                    if(errorCode=='0'){
                        let inde = this.state.departmentforchoose.indexOf(depid);
                        this.props.onchose(depid,inde)
                    }
                }
            }
        );
    }
    
    render(){
        return (
            <Modal maskClosable={false} visible={this.state.visible}
                   className="people_muchforbid--modal close_style_modal" onOk={this.createuser.bind(this)}
                   onCancel={this.handleCancel} style={{width:"634px",height:"240px",display:"block"}}
                   title={"批量修改部门"}
            >
                <p  className="re_font--MicYaHei" style={{width:200,marginLeft:65}}>员工总数<span>{this.state.uidlist.length}</span>人</p>
                <span className="title_option" style={{position:"absolute",display:"block",left:43,top:115}}>部门</span>
                <div className="people_muchmodifypart--select">
                    <Select var oArr={this.state.departname} style={{width:338,height:30,display:"inlineBlock",marginTop:20,marginLeft:64}} defaultValue={this.state.partid} ref={'partname'}/>
                </div>
            </Modal>
        )
    }
}




